package com.maxsalad.baidu.service;

import com.maxsalad.baidu.entity.RequestCmd;
import com.maxsalad.baidu.entity.dish.list.ResponseDishListEntity;
import com.maxsalad.baidu.entity.sku.list.ResponseSkuListEntity;
import com.maxsalad.common.util.JsonUtil;
import com.maxsalad.common.util.OkHttpUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * Created by Administrator on 2016-3-12.
 */
public class SkuService extends BaseService {
    private static final Logger log = LoggerFactory.getLogger(SkuService.class);

    public ResponseSkuListEntity getSkuList(String shopId) throws Exception {
        Map param = new HashMap();
        param.put("shop_id", shopId);
        param.put("page", "1");

        RequestCmd cmd = new RequestCmd();
        cmd.setCmd("sku.list");
        cmd.setSource(getSource());
        cmd.setSecret(getSecret());
        cmd.setTimestamp((int) (System.currentTimeMillis() / 1000L));
        cmd.setTicket(UUID.randomUUID().toString().toUpperCase());
        cmd.setBody(param);

        String sign = getSign(cmd);
        cmd.setSign(sign);
        log.debug(sign);

        String json = OkHttpUtil.post(getBaseUrl(), JsonUtil.serialize(cmd));
        log.debug(json);

        return (ResponseSkuListEntity) JsonUtil.deserialize(json, ResponseSkuListEntity.class);
    }
}
